package com.sg.service.biz.component.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.component.req.*;
import com.sg.dto.biz.component.res.*;
import com.sg.service.base.component.MCustomFields3Service;
import com.sg.service.biz.component.InterfaceModeService;
import com.sg.service.biz.component.nb.NbMobileEndShell;
import com.sg.common.exception.Assert;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.stream.Collectors;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class MobileEndShellServiceImpl
        implements com.wicket.okrcomponent.biz.service.MobileEndShellService {

    @Resource
    private RedisUtil redisUtil;
    @Resource
    private InterfaceModeService interfaceModeService;
    @Resource
    private MCustomFields3Service mCustomFields3Service;
    @Resource
    private NbMobileEndShell nbMobileEndShell;

    /**
     * D2执行组合去重部门就职记录(公共)[9018]
     * gen by moon at 4/1/2024, 1:35:34 AM
     */
    @Trace(operationName = "D2执行组合去重部门就职记录(公共)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ImplementGroupDeduplicationRecordCircularCombinationDeptComRespDto implementGroupDeduplicationRecordCircularCombinationDeptCom(ImplementGroupDeduplicationRecordCircularCombinationDeptComReqDto reqDto) {


        ImplementManyFieldsDataSetDuplicateRemovalComRespDto implementManyFieldsDataSetDuplicateRemovalComRespDto_1 = null;
        if ((reqDto != null && reqDto.getDataSetsListOne() != null && reqDto.getDataSetsListOne().size() > 0 && reqDto != null && reqDto.getDataSetsListTwo() != null && reqDto.getDataSetsListTwo().size() > 0)) {
            //if((D2执行组合去重部门就职记录(公共).数据集列表一数据集条数 大于 0 and D2执行组合去重部门就职记录(公共).数据集列表二数据集条数 大于 0))  65833

            ImplementUnionMultipleDataSetsComRespDto implementUnionMultipleDataSetsComRespDto = null;
            ImplementUnionMultipleDataSetsComReqDto implementUnionMultipleDataSetsComReqDto = new ImplementUnionMultipleDataSetsComReqDto();
            if (reqDto != null && reqDto.getDataSetsListOne() != null && !CollectionUtil.isEmpty(reqDto.getDataSetsListOne())) {
                implementUnionMultipleDataSetsComReqDto.setDataSetsListOne(//objList-to-objLists
                        reqDto.getDataSetsListOne().stream().map(item -> {
                            DataSetsListOneDto elm = new DataSetsListOneDto();
                            if (item != null) {
                                elm.setCustomField(item.getInductionRecordId() != null ? String.valueOf(item.getInductionRecordId()) : "");//SimpleFieldAssign//sourceId:327342_2_65834
                                elm.setCustomField1(item.getDeptId() != null ? String.valueOf(item.getDeptId()) : "");//SimpleFieldAssign//sourceId:327341_2_65834
                                elm.setCustomField2(item.getOriginalRoleMemberId() != null ? String.valueOf(item.getOriginalRoleMemberId()) : "");//SimpleFieldAssign//sourceId:327343_2_65834
                            }
                            return elm;
                        }).collect(Collectors.toList()));//objList-to-objLists//sourceId:1681894_1_65834
            }
            if (reqDto != null && reqDto.getDataSetsListTwo() != null && !CollectionUtil.isEmpty(reqDto.getDataSetsListTwo())) {
                implementUnionMultipleDataSetsComReqDto.setDataSetsListTwo(//objList-to-objLists
                        reqDto.getDataSetsListTwo().stream().map(item -> {
                            DataSetsListTwoDto elm = new DataSetsListTwoDto();
                            if (item != null) {
                                elm.setCustomField(item.getInductionRecordId() != null ? String.valueOf(item.getInductionRecordId()) : "");//SimpleFieldAssign//sourceId:327347_2_65834
                                elm.setCustomField1(item.getOneDeptId() != null ? String.valueOf(item.getOneDeptId()) : "");//SimpleFieldAssign//sourceId:327348_2_65834
                                elm.setCustomField2(item.getOriginalRoleMemberId() != null ? String.valueOf(item.getOriginalRoleMemberId()) : "");//SimpleFieldAssign//sourceId:327345_2_65834
                            }
                            return elm;
                        }).collect(Collectors.toList()));//objList-to-objLists//sourceId:1681895_1_65834
            }

            /*D2执行就职记录部门与冗余的一级部门数据集相加[5320]   */

            implementUnionMultipleDataSetsComRespDto = interfaceModeService.implementUnionMultipleDataSetsCom(implementUnionMultipleDataSetsComReqDto)/*vcase invoke isSameApp*/;
            Assert.isTrue(implementUnionMultipleDataSetsComRespDto == null || implementUnionMultipleDataSetsComRespDto.getUnionMultipleDataSetsList() == null || CollectionUtil.isEmpty(implementUnionMultipleDataSetsComRespDto.getUnionMultipleDataSetsList()) || implementUnionMultipleDataSetsComRespDto.getUnionMultipleDataSetsList().size() == 0, "找不到数据，系统异常", false);


            ImplementManyFieldsDataSetDuplicateRemovalComRespDto implementManyFieldsDataSetDuplicateRemovalComRespDto = null;
            if (implementUnionMultipleDataSetsComRespDto != null) {
                ImplementManyFieldsDataSetDuplicateRemovalComReqDto implementManyFieldsDataSetDuplicateRemovalComReqDto = new ImplementManyFieldsDataSetDuplicateRemovalComReqDto();
                if (implementUnionMultipleDataSetsComRespDto != null && implementUnionMultipleDataSetsComRespDto.getUnionMultipleDataSetsList() != null && !CollectionUtil.isEmpty(implementUnionMultipleDataSetsComRespDto.getUnionMultipleDataSetsList())) {
                    implementManyFieldsDataSetDuplicateRemovalComReqDto.setDataSetDuplicateRemovalList(//objList-to-objLists
                            implementUnionMultipleDataSetsComRespDto.getUnionMultipleDataSetsList().stream().map(item -> {
                                DataSetDuplicateRemovalDto elm = new DataSetDuplicateRemovalDto();
                                if (item != null) {
                                    elm.setCommPrimaryKey(item.getCustomField1());//SimpleFieldAssign//sourceId:327353_2_65835
                                    elm.setCustomField1(item.getCustomField());//SimpleFieldAssign//sourceId:327354_2_65835
                                    elm.setCustomField2(item.getCustomField2());//SimpleFieldAssign//sourceId:327355_2_65835
                                }
                                return elm;
                            }).collect(Collectors.toList()));//objList-to-objLists//sourceId:1681902_1_65835
                }

                /*D2执行多字段数据集记录去重(公共)[7323]   */

                implementManyFieldsDataSetDuplicateRemovalComRespDto = interfaceModeService.implementManyFieldsDataSetDuplicateRemovalCom(implementManyFieldsDataSetDuplicateRemovalComReqDto)/*vcase invoke isSameApp*/;


                implementManyFieldsDataSetDuplicateRemovalComRespDto_1 = implementManyFieldsDataSetDuplicateRemovalComRespDto;
            }
        }
        ImplementGroupDeduplicationRecordCircularCombinationDeptComRespDto retData = new ImplementGroupDeduplicationRecordCircularCombinationDeptComRespDto();
        if (implementManyFieldsDataSetDuplicateRemovalComRespDto_1 != null) {
            retData.setDataSetDuplicateRemovalList(//objList-to-objLists
                    implementManyFieldsDataSetDuplicateRemovalComRespDto_1.getDataSetDuplicateRemovalList().stream().map(item -> {
                        DataSetDuplicateRemovalDto elm = new DataSetDuplicateRemovalDto();
                        if (item != null) {
                            elm.setInductionRecordId(item.getCustomField1());//SimpleFieldAssign//sourceId:327498_2
                            elm.setDeptId(item.getCommPrimaryKey());//SimpleFieldAssign//sourceId:327497_2
                            elm.setOriginalRoleMemberId(item.getCustomField2());//SimpleFieldAssign//sourceId:327499_2
                        }
                        return elm;
                    }).collect(Collectors.toList()));//objList-to-objLists//sourceId:1682110_1
        }


        return retData;
    }

    /**
     * D2执行调整主导航排序(公共)[8988]
     * gen by moon at 4/1/2024, 2:23:25 AM
     */
    @Trace(operationName = "D2执行调整主导航排序(公共)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ImplementAdjustMainNavigationSortingComRespDto implementAdjustMainNavigationSortingCom(ImplementAdjustMainNavigationSortingComReqDto reqDto) {


        ImplementAdjustMainNavigationSortingRespDto adjustMainNavigationSortingRes_1 = null;
//步骤0: M2执行调整主导航排序（特殊方法） - implementAdjustMainNavigationSorting
        //ModelCode: adjustMainNavigationSorting
        ImplementAdjustMainNavigationSortingRespDto adjustMainNavigationSortingRes = null;
        ImplementAdjustMainNavigationSortingReqDto adjustMainNavigationSortingReq = new ImplementAdjustMainNavigationSortingReqDto();
        if (reqDto != null && reqDto.getAdjustMainNavigationSortingList() != null && !CollectionUtil.isEmpty(reqDto.getAdjustMainNavigationSortingList())) {
            adjustMainNavigationSortingReq.setAdjustMainNavigationSortingList(//objList-to-objLists
                    reqDto.getAdjustMainNavigationSortingList().stream().map(item -> {
                        AdjustMainNavigationSortingDto elm = new AdjustMainNavigationSortingDto();
                        if (item != null) {
                            elm.setCustomField1(item.getMenuCode() != null ? String.valueOf(item.getMenuCode()) : "");//SimpleFieldAssign//sourceId:326155_2
                            elm.setCustomField2(item.getMenuName() != null ? String.valueOf(item.getMenuName()) : "");//SimpleFieldAssign//sourceId:326156_2
                            elm.setCustomField3(item.getMenuIcon() != null ? String.valueOf(item.getMenuIcon()) : "");//SimpleFieldAssign//sourceId:326157_2
                            elm.setCustomField4(item.getMenuIsVisible() != null ? String.valueOf(item.getMenuIsVisible()) : "");//SimpleFieldAssign//sourceId:326158_2
                            elm.setCustomField5(item.getMenuPath() != null ? String.valueOf(item.getMenuPath()) : "");//SimpleFieldAssign//sourceId:326159_2
                            elm.setCustomField6(item.getMenuOrderNumber() != null ? String.valueOf(item.getMenuOrderNumber()) : "");//SimpleFieldAssign//sourceId:326160_2
                        }
                        return elm;
                    }).collect(Collectors.toList()));//objList-to-objLists//sourceId:1679251_1
        }
        if (reqDto != null && reqDto.getAgreedNavigationSortingDatasetList() != null && !CollectionUtil.isEmpty(reqDto.getAgreedNavigationSortingDatasetList())) {
            adjustMainNavigationSortingReq.setAgreedNavigationSortingDatasetList(//objList-to-objLists
                    reqDto.getAgreedNavigationSortingDatasetList().stream().map(item -> {
                        AgreedNavigationSortingDatasetDto elm = new AgreedNavigationSortingDatasetDto();
                        if (item != null) {
                            elm.setCustomField1(item.getMenuCode() != null ? String.valueOf(item.getMenuCode()) : "");//SimpleFieldAssign//sourceId:326161_2
                            elm.setCustomField2(item.getMenuOrderNumber() != null ? String.valueOf(item.getMenuOrderNumber()) : "");//SimpleFieldAssign//sourceId:326162_2
                        }
                        return elm;
                    }).collect(Collectors.toList()));//objList-to-objLists//sourceId:1679252_1
        }
        if (reqDto != null) {
            adjustMainNavigationSortingReq.setCustomField1(reqDto.getMyLeaderPlan());//SimpleFieldAssign//sourceId:1679253_1
            adjustMainNavigationSortingReq.setCustomField2(reqDto.getMySubordinatePlan());//SimpleFieldAssign//sourceId:1679254_1
            adjustMainNavigationSortingReq.setCustomField3(reqDto.getMyDeptPlan());//SimpleFieldAssign//sourceId:1679434_1
            adjustMainNavigationSortingReq.setCustomField4(reqDto.getSpacePlan());//SimpleFieldAssign//sourceId:1680452_1
        }

        /*M2执行调整主导航排序（特殊方法）[8990]   */

        adjustMainNavigationSortingRes = nbMobileEndShell.implementAdjustMainNavigationSorting(adjustMainNavigationSortingReq);


        adjustMainNavigationSortingRes_1 = adjustMainNavigationSortingRes;

        ImplementAdjustMainNavigationSortingComRespDto retData = new ImplementAdjustMainNavigationSortingComRespDto();
        if (adjustMainNavigationSortingRes_1 != null) {
            retData.setAdjustMainNavigationSortingList(//objList-to-objLists
                    adjustMainNavigationSortingRes_1.getAdjustMainNavigationSortingList().stream().map(item -> {
                        AdjustMainNavigationSortingDto elm = new AdjustMainNavigationSortingDto();
                        if (item != null) {
                            elm.setMenuCode(item.getCustomField1());//SimpleFieldAssign//sourceId:326177_2
                            elm.setMenuName(item.getCustomField2());//SimpleFieldAssign//sourceId:326178_2
                            elm.setMenuIcon(item.getCustomField3());//SimpleFieldAssign//sourceId:326179_2
                            elm.setMenuIsVisible(item.getCustomField4());//SimpleFieldAssign//sourceId:326180_2
                            elm.setMenuPath(item.getCustomField5());//SimpleFieldAssign//sourceId:326181_2
                            elm.setMenuOrderNumber(item.getCustomField6());//SimpleFieldAssign//sourceId:326182_2
                        }
                        return elm;
                    }).collect(Collectors.toList()));//objList-to-objLists//sourceId:1679261_1
        }


        return retData;
    }
    //
}
